package com.threeox.commonlibrary.entity.engine.event;

import android.content.Context;

import com.alibaba.fastjson.JSONObject;
import com.threeox.commonlibrary.entity.base.BaseObj;
import com.threeox.commonlibrary.util.BroadCastUtils;
import com.threeox.commonlibrary.util.RegexHelper;
import com.threeox.utillibrary.util.res.StringHelper;

/**
 * 
 * @ClassName: BroadCastMessage
 * 
 * @Description: TODO(广播通知的对象)
 * 
 * @author 赵屈犇
 * 
 * @date 创建时间: 2017/10/11 12:53
 * 
 * @version 1.0
 * 
 */
public class BroadCastMessage extends BaseObj {

    private String action;// 通知的action
    private JSONObject params;// 传递参数

    private JSONObject paramsKeys;//可以替换的主键集合

    public void initData(StringHelper stringHelper) {
        try {
            this.action = stringHelper.getStringText(action);
            paramsKeys = RegexHelper.getReplaceKeys(params);
            RegexHelper.replaceSys(params);
        } catch (Exception e) {
        }
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public JSONObject getParams() {
        return params;
    }

    public void setParams(JSONObject params) {
        this.params = params;
    }

    /**
     * 设置参数
     *
     * @param key
     * @param value
     */
    public void putParams(String key, Object value) {
        if (params == null) {
            params = new JSONObject();
        }
        params.put(key, value);
    }

    /**
     * 初始化參數
     *
     * @param data
     */
    public void initParam(Object data) {
        RegexHelper.replace(this.params, this.paramsKeys, data);
    }

    /**
     * 启动Activity
     *
     * @param context
     */
    public void sendBroadCast(Context context) {
        BroadCastUtils.getInstance(context).putIntent(params).sendBroadCast(action);
    }

}
